package com.ktgj.pay.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.pay.domain.InvoiceDelivery;
import com.ktgj.pay.service.IInvoiceDeliveryService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 发票配送Controller
 * 
 * @author ruoyi
 * @date 2022-01-24
 */
@RestController
@RequestMapping("/delivery")
public class InvoiceDeliveryController extends BaseController
{
    @Autowired
    private IInvoiceDeliveryService invoiceDeliveryService;

    /**
     * 查询发票配送列表
     */
    @PreAuthorize(hasPermi = "invoice:delivery:list")
    @GetMapping("/list")
    public TableDataInfo list(InvoiceDelivery invoiceDelivery)
    {
        startPage();
        List<InvoiceDelivery> list = invoiceDeliveryService.selectInvoiceDeliveryList(invoiceDelivery);
        return getDataTable(list);
    }

    /**
     * 导出发票配送列表
     */
    @PreAuthorize(hasPermi = "invoice:delivery:export")
    @Log(title = "发票配送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvoiceDelivery invoiceDelivery) throws IOException
    {
        List<InvoiceDelivery> list = invoiceDeliveryService.selectInvoiceDeliveryList(invoiceDelivery);
        ExcelUtil<InvoiceDelivery> util = new ExcelUtil<InvoiceDelivery>(InvoiceDelivery.class);
        util.exportExcel(response, list, "发票配送数据");
    }

    /**
     * 获取发票配送详细信息
     */
    @PreAuthorize(hasPermi = "invoice:delivery:query")
    @GetMapping(value = "/{deliveryid}")
    public AjaxResult getInfo(@PathVariable("deliveryid") Long deliveryid)
    {
        return AjaxResult.success(invoiceDeliveryService.selectInvoiceDeliveryById(deliveryid));
    }

    /**
     * 新增发票配送
     */
    @PreAuthorize(hasPermi = "invoice:delivery:add")
    @Log(title = "发票配送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvoiceDelivery invoiceDelivery)
    {
        return toAjax(invoiceDeliveryService.insertInvoiceDelivery(invoiceDelivery));
    }

    /**
     * 修改发票配送
     */
    @PreAuthorize(hasPermi = "invoice:delivery:edit")
    @Log(title = "发票配送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvoiceDelivery invoiceDelivery)
    {
        return toAjax(invoiceDeliveryService.updateInvoiceDelivery(invoiceDelivery));
    }

    /**
     * 删除发票配送
     */
    @PreAuthorize(hasPermi = "invoice:delivery:remove")
    @Log(title = "发票配送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deliveryids}")
    public AjaxResult remove(@PathVariable Long[] deliveryids)
    {
        return toAjax(invoiceDeliveryService.deleteInvoiceDeliveryByIds(deliveryids));
    }

    /**
     * 通过机票订单id查询发票配送状态
     * @param orderId
     * @return
     */
    @PostMapping("/queryEmailState")
    public int queryEmailState(@RequestParam("orderId") Long orderId) {
        return invoiceDeliveryService.queryEmailState(orderId);
    }
}
